const { NestFactory } = require('@nestjs/core');
const { AppModule } = require('./dist/app.module');
const { DocumentBuilder, SwaggerModule } = require('@nestjs/swagger');

async function testSwagger() {
  try {
    console.log('🚀 正在启动应用...');
    const app = await NestFactory.create(AppModule);
    
    console.log('📚 配置Swagger...');
    const config = new DocumentBuilder()
      .setTitle('RWA Admin Backend API')
      .setDescription('RWA管理系统后端API文档')
      .setVersion('1.0')
      .addTag('认证', '用户认证相关接口')
      .addTag('用户管理', '用户管理相关接口')
      .addTag('角色管理', '角色管理相关接口')
      .addTag('权限管理', '权限管理相关接口')
      .addTag('MongoDB', 'MongoDB数据库操作接口')
      .addBearerAuth()
      .build();

    const document = SwaggerModule.createDocument(app, config);
    SwaggerModule.setup('api-docs', app, document);
    
    console.log('✅ Swagger配置成功！');
    console.log('📖 API文档地址: http://localhost:8085/api-docs');
    
    // 检查文档内容
    const paths = Object.keys(document.paths || {});
    console.log(`📊 发现 ${paths.length} 个API端点:`);
    paths.forEach(path => {
      const methods = Object.keys(document.paths[path] || {});
      console.log(`  ${path}: ${methods.join(', ')}`);
    });
    
  } catch (error) {
    console.error('❌ 测试失败:', error.message);
    process.exit(1);
  }
}

testSwagger();
